package com.example.mutilitemdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        intiView();
    }
    private void intiView(){
        RecyclerView chatList=findViewById(R.id.chat_list);
        EditText text=findViewById(R.id.text_chat_send);
        Button button=findViewById(R.id.button_chat_send);

        chatList.setLayoutManager(new LinearLayoutManager(this));
        List<ChatMsgModel> list=new ArrayList<>();
        ChatMsgAdapter chatMsgAdapter=new ChatMsgAdapter(this);
        chatMsgAdapter.setList(list);
        chatList.setAdapter(chatMsgAdapter);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content=text.getText().toString();
                if (TextUtils.isEmpty(content)){
                    return;
                }
                ChatMsgModel model=new ChatMsgModel();
                model.setMsgTextContent(content);
                model.setSendOrRecv(true);
                list.add(model);
                 ChatMsgModel auto=new ChatMsgModel();
                 auto.setMsgTextContent("有点忙，稍后回复");
                 auto.setSendOrRecv(false);
                 list.add(auto);
                 chatMsgAdapter.notifyDataSetChanged();
            }
        });

    }
}